﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entities;
using System.Web.Script.Serialization;
public partial class ShoppingCart : System.Web.UI.Page
    {
        private ProductManager blProduct = null;
        protected void Page_Load(object sender, EventArgs e)
        {

            blProduct = new ProductManager();
            if (Request.QueryString["productID"] != null)
            {
                int id = Convert.ToInt32(Request.QueryString["productID"].ToString());
                int quantity = Convert.ToInt32(Request.QueryString["Quantity"].ToString());
                Product p = blProduct.GetProductById(id);
                BLShoppingCart cart;
                if (Session["cart"] == null)
                {
                    cart = new BLShoppingCart();
                }
                else
                {
                    cart = (BLShoppingCart)Session["cart"];
                }
                cart.Add(p.ProductID, p.ProductName, quantity, decimal.Parse(p.ProductPrice.ToString()), p.imageLink);
                Session["cart"] = cart;
                string totalPrice = String.Format("{0:C}",cart.TotalPayment().ToString());
                string totalQuantity = cart.TotalQuantity().ToString();
                string response = totalQuantity + ":" + totalPrice;
                Response.Write(response);
                Response.End();
            }
        }
    }
